/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package design;

import Dao.Dangnhap;
import Dao.ketquaDao;
import Entity.ketqua;
import Util.ConSQL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author use
 */
public class frmNhapdiem extends javax.swing.JFrame {

    /**
     * Creates new form frmNhapdiem
     */
    String maGV;
    String tenGV;
    String matkhau;
    Dangnhap dn = new Dangnhap();
    ConSQL conn = new ConSQL();
    ketquaDao kq = new ketquaDao();
    private DefaultTableModel tableModel;
    DefaultComboBoxModel cmModel = new DefaultComboBoxModel();
    private ArrayList<ketqua> aLoad;
    private ketqua kqe = new ketqua();

    public frmNhapdiem() throws Exception {
        initComponents();
        kq.cbbLopHocPhan(cbbDanhsachlopHP);
        kq.cbbmonHoc(cbbmonhoc);
        kq.cbbsinhvien(cbbsinhvien);
        loadData();
        //
        this.setLocationRelativeTo(null);
    }
    //

    public frmNhapdiem(String maGV, String tenGV, String matkhau) throws Exception {
        initComponents();
        kq.cbbLopHocPhan(cbbDanhsachlopHP);
        kq.cbbmonHoc(cbbmonhoc);
        kq.cbbsinhvien(cbbsinhvien);
        this.setSize(1100, 650);
        //
        this.maGV = maGV;
        this.tenGV = tenGV;
        this.matkhau = matkhau;
        //
        lbMaGV.setText(maGV);
        lbTen.setText(tenGV);
        loadData();
    }
    //

    private void loadData() {
        tableModel = new DefaultTableModel();
        tableModel.setRowCount(0);
        Vector col = new Vector();
        col.addElement("Mã Môn học");
        col.addElement("Mã SV");
        col.addElement("Học kì");
        col.addElement("Điểm chuyên cần");
        col.addElement("Điểm giữa kì");
        col.addElement("Điểm KTHP");
        col.addElement("Điểm TB");
        col.addElement("Xếp loại");
        col.addElement("Điểm tích luỹ");
        col.addElement("Ghi chú");
        tableModel.setColumnIdentifiers(col);
        aLoad = new ketquaDao().selectAll();
        for (int i = 0; i < aLoad.size(); i++) {
            kqe = aLoad.get(i);
            Vector row = new Vector();
            row.addElement(kqe.getMaMH());
            row.addElement(kqe.getMaSV());
            
            row.addElement(kqe.getHocKy());
            row.addElement(kqe.getDChuyencan());
            row.addElement(kqe.getDGiuaky());
            row.addElement(kqe.getDThiKetthuc());
            row.addElement(kqe.getDTrungBinh());
            row.addElement(kqe.getXepLoai());
            row.addElement(kqe.getDTichLuy());
            row.addElement(kqe.getGhiChu());
            tableModel.addRow(row);
        }
        tbDanhsachSV.setModel(tableModel);
    }

    private void insertData() {
        float DChuyenCan = Float.parseFloat(txtdiemchuyencan.getText());
        float DGiuaKi = Float.parseFloat(txtdiemgiuaki.getText());
        float DKTHP = Float.parseFloat(txtdiemthiketthuc.getText());
        float DTB = Float.parseFloat(txtdiemTB.getText());
        float DTichluy = Float.parseFloat(txtdtichluy.getText());
        int hocki = Integer.parseInt(cbbhocki.getSelectedItem().toString());
        String xepLoai = txtxeploai.getText();
        String ghiChu = txtghichu.getText();
        String maSV = cbbsinhvien.getSelectedItem().toString();
        String maMH = cbbmonhoc.getSelectedItem().toString();

        kqe.setMaMH(maMH);
        kqe.setMaSV(maSV);
        kqe.setHocKy(hocki);
        kqe.setDChuyencan(DChuyenCan);
        kqe.setDGiuaky(DGiuaKi);
        kqe.setDThiKetthuc(DTichluy);
        kqe.setDTrungBinh(DTB);
        kqe.setXepLoai(xepLoai);
        kqe.setDTichLuy(DTichluy);
        kqe.setGhiChu(ghiChu);
        ketquaDao dao = new ketquaDao();
        if (dao.nhapdiem(kqe)) {
            JOptionPane.showMessageDialog(null, "nhập điểm thành công");
            loadData();
        } else {
            JOptionPane.showMessageDialog(null, "nhập điểm thất bại");
        }

        cbbDanhsachlopHP.setSelectedIndex(0);
        cbbhocki.setSelectedIndex(0);
        cbbmonhoc.setSelectedIndex(0);
        cbbsinhvien.setSelectedIndex(0);
        txtdiemTB.setText(null);
        txtdiemchuyencan.setText(null);
        txtdiemgiuaki.setText(null);
        txtdiemthiketthuc.setText(null);
        txtdtichluy.setText(null);
        txtghichu.setText(null);
        txtxeploai.setText(null);



    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        pnThongtin = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lbTen = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lbMaGV = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbDanhsachSV = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        cbbDanhsachlopHP = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cbbmonhoc = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtdiemchuyencan = new javax.swing.JTextField();
        txtdiemgiuaki = new javax.swing.JTextField();
        txtdiemthiketthuc = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cbbsinhvien = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtdiemTB = new javax.swing.JTextField();
        txtdtichluy = new javax.swing.JTextField();
        txtxeploai = new javax.swing.JTextField();
        txtghichu = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        cbbhocki = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        btnnhapdiem = new javax.swing.JButton();
        btnCapnhatDiem = new javax.swing.JButton();
        btnthoat = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new java.awt.CardLayout());

        pnThongtin.setBackground(new java.awt.Color(255, 255, 255));
        pnThongtin.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin giáo viên", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 0, 204))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Họ tên:");

        lbTen.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbTen.setText("Tên");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Mã giáo viên:");

        lbMaGV.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbMaGV.setText("Mã giáo viên");

        javax.swing.GroupLayout pnThongtinLayout = new javax.swing.GroupLayout(pnThongtin);
        pnThongtin.setLayout(pnThongtinLayout);
        pnThongtinLayout.setHorizontalGroup(
            pnThongtinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnThongtinLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnThongtinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(pnThongtinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnThongtinLayout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(lbMaGV, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE))
                    .addGroup(pnThongtinLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(lbTen, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)))
                .addContainerGap())
        );
        pnThongtinLayout.setVerticalGroup(
            pnThongtinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnThongtinLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnThongtinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lbMaGV))
                .addGap(18, 18, 18)
                .addGroup(pnThongtinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnThongtinLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(lbTen)
                        .addGap(75, 75, 75))
                    .addGroup(pnThongtinLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh sách sinh viên", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 0, 204))); // NOI18N

        tbDanhsachSV.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbDanhsachSV.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbDanhsachSVMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tbDanhsachSV);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 11, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin lớp học phần", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 0, 204))); // NOI18N

        cbbDanhsachlopHP.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbbDanhsachlopHP.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbDanhsachlopHPItemStateChanged(evt);
            }
        });
        cbbDanhsachlopHP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbbDanhsachlopHPActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Lớp học phần :");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Mã Môn học:");

        cbbmonhoc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbbmonhoc.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbmonhocItemStateChanged(evt);
            }
        });
        cbbmonhoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbbmonhocActionPerformed(evt);
            }
        });

        jLabel3.setText("Điểm chuyên cần:");

        jLabel4.setText("Điểm giữa kì:");

        jLabel7.setText("Điểm thi kết thúc HP:");

        txtdiemchuyencan.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtdiemchuyencanKeyTyped(evt);
            }
        });

        txtdiemgiuaki.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtdiemgiuakiKeyTyped(evt);
            }
        });

        txtdiemthiketthuc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtdiemthiketthucKeyTyped(evt);
            }
        });

        jLabel8.setText("Mã sinh viên:");

        cbbsinhvien.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel9.setText("Điểm trung bình:");

        jLabel10.setText("Xếp loại:");

        jLabel11.setText("Điểm tích luỹ:");

        jLabel12.setText("Ghi chú:");

        txtdiemTB.setEnabled(false);

        txtdtichluy.setEnabled(false);

        txtxeploai.setEnabled(false);

        txtghichu.setEnabled(false);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel13.setText("Kì:");

        cbbhocki.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8" }));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel11))
                .addGap(59, 59, 59)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cbbDanhsachlopHP, 0, 145, Short.MAX_VALUE)
                    .addComponent(txtdiemchuyencan)
                    .addComponent(cbbsinhvien, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtdiemTB)
                    .addComponent(txtdtichluy))
                .addGap(71, 71, 71)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel12))
                        .addGap(83, 83, 83)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtxeploai, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtghichu, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(51, 51, 51)
                                .addComponent(cbbmonhoc, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addGap(111, 111, 111)
                                .addComponent(cbbhocki, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(59, 59, 59)
                                .addComponent(txtdiemgiuaki)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel7)
                        .addGap(23, 23, 23)
                        .addComponent(txtdiemthiketthuc, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbmonhoc, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel2)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(cbbDanhsachlopHP, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(cbbsinhvien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel13))
                    .addComponent(cbbhocki, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(txtdiemthiketthuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(txtdiemgiuaki, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(txtdiemchuyencan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(35, 35, 35)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(txtdiemTB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtxeploai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(txtdtichluy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtghichu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21))
        );

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Chức năng", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 0, 153))); // NOI18N

        btnnhapdiem.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnnhapdiem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add-icon.png"))); // NOI18N
        btnnhapdiem.setText("Nhập điểm");
        btnnhapdiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnnhapdiemActionPerformed(evt);
            }
        });

        btnCapnhatDiem.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnCapnhatDiem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/update.png"))); // NOI18N
        btnCapnhatDiem.setText("Cập nhật điểm");
        btnCapnhatDiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCapnhatDiemActionPerformed(evt);
            }
        });

        btnthoat.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnthoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit.png"))); // NOI18N
        btnthoat.setText("Thoát");
        btnthoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnthoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnnhapdiem)
                .addGap(38, 38, 38)
                .addComponent(btnCapnhatDiem)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 497, Short.MAX_VALUE)
                .addComponent(btnthoat, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnnhapdiem, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCapnhatDiem, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnthoat, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(pnThongtin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 635, Short.MAX_VALUE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnThongtin, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(jPanel1, "card2");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbbDanhsachlopHPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbbDanhsachlopHPActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbbDanhsachlopHPActionPerformed

    private void cbbDanhsachlopHPItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbDanhsachlopHPItemStateChanged
        // TODO add your handling code here:   
    }//GEN-LAST:event_cbbDanhsachlopHPItemStateChanged

    private void cbbmonhocItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbmonhocItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_cbbmonhocItemStateChanged

    private void cbbmonhocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbbmonhocActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbbmonhocActionPerformed

    private void btnthoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnthoatActionPerformed
        // TODO add your handling code here:
        new frmGiaovien(maGV, tenGV, matkhau).setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_btnthoatActionPerformed

    private void btnCapnhatDiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCapnhatDiemActionPerformed
        // TODO add your handling code here:
        float DChuyenCan = Float.parseFloat(txtdiemchuyencan.getText());
        float DGiuaKi = Float.parseFloat(txtdiemgiuaki.getText());
        float DKTHP = Float.parseFloat(txtdiemthiketthuc.getText());
        float DTB = Float.parseFloat(txtdiemTB.getText());
        float DTichluy = Float.parseFloat(txtdtichluy.getText());
        int hocki = Integer.parseInt(cbbhocki.getSelectedItem().toString());
        String xepLoai = txtxeploai.getText();
        String ghiChu = txtghichu.getText();
        String maSV = cbbsinhvien.getSelectedItem().toString();
        String maMH = cbbmonhoc.getSelectedItem().toString();

        kqe.setMaMH(maMH);
        kqe.setMaSV(maSV);
        kqe.setHocKy(hocki);
        kqe.setDChuyencan(DChuyenCan);
        kqe.setDGiuaky(DGiuaKi);
        kqe.setDThiKetthuc(DTichluy);
        kqe.setDTrungBinh(DTB);
        kqe.setXepLoai(xepLoai);
        kqe.setDTichLuy(DTichluy);
        kqe.setGhiChu(ghiChu);
        ketquaDao dao = new ketquaDao();
        if (dao.update(kqe)) {
            JOptionPane.showMessageDialog(null, "cập nhật thành công");
            loadData();
        } else {
            JOptionPane.showMessageDialog(null, "cập nhật thất bại");
        }
         cbbDanhsachlopHP.setSelectedIndex(0);
        cbbhocki.setSelectedIndex(0);
        cbbmonhoc.setSelectedIndex(0);
        cbbsinhvien.setSelectedIndex(0);
        txtdiemTB.setText(null);
        txtdiemchuyencan.setText(null);
        txtdiemgiuaki.setText(null);
        txtdiemthiketthuc.setText(null);
        txtdtichluy.setText(null);
        txtghichu.setText(null);
        txtxeploai.setText(null);
    }//GEN-LAST:event_btnCapnhatDiemActionPerformed

    private void btnnhapdiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnnhapdiemActionPerformed
        // TODO add your handling code here:
        float DChuyenCan = Float.parseFloat(txtdiemchuyencan.getText());
        float DGiuaKi = Float.parseFloat(txtdiemgiuaki.getText());
        float DKTHP = Float.parseFloat(txtdiemthiketthuc.getText());
        float DTB = (float) (DChuyenCan * 0.2 + DGiuaKi * 0.2 + DKTHP * 0.6);
        String sDTB = Float.toString(DTB);
        if ((DChuyenCan > 0 && DChuyenCan < 10) || (DGiuaKi > 0 && DGiuaKi < 10) || (DKTHP > 0 && DKTHP < 10)) {
            if (DTB >= 8.5) {
                txtdiemTB.setText(sDTB);
                txtxeploai.setText("A");
                txtdtichluy.setText("4.0");
                txtghichu.setText(null);
                insertData();
            } else if (DTB >= 6.5 && DTB < 8.5) {
                txtdiemTB.setText(sDTB);
                txtxeploai.setText("B");
                txtdtichluy.setText("3.0");
                txtghichu.setText(null);
                insertData();
            } else if (DTB >= 5.0 && DTB < 6.5) {
                txtdiemTB.setText(sDTB);
                txtxeploai.setText("C");
                txtdtichluy.setText("2.0");
                txtghichu.setText(null);
                insertData();
            } else if (DTB >= 3.5 && DTB < 5.0) {
                txtdiemTB.setText(sDTB);
                txtxeploai.setText("D");
                txtdtichluy.setText("1.0");
                txtghichu.setText(null);
                insertData();
            } else {
                txtdiemTB.setText(sDTB);
                txtxeploai.setText("F");
                txtdtichluy.setText("0.0");
                txtghichu.setText("Thi Lại");
                insertData();
            }
        } else {
            JOptionPane.showMessageDialog(this, "Bạn phải nhập số >0 và <10!");
        }

    }//GEN-LAST:event_btnnhapdiemActionPerformed

    private void txtdiemchuyencanKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdiemchuyencanKeyTyped
        // TODO add your handling code here:
        if (!Character.isDigit(evt.getKeyChar())) {
            evt.consume();
        }
    }//GEN-LAST:event_txtdiemchuyencanKeyTyped

    private void txtdiemgiuakiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdiemgiuakiKeyTyped
        // TODO add your handling code here:
        if (!Character.isDigit(evt.getKeyChar())) {
            evt.consume();
        }
    }//GEN-LAST:event_txtdiemgiuakiKeyTyped

    private void txtdiemthiketthucKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdiemthiketthucKeyTyped
        // TODO add your handling code here:
        if (!Character.isDigit(evt.getKeyChar())) {
            evt.consume();
        }
    }//GEN-LAST:event_txtdiemthiketthucKeyTyped

    private void tbDanhsachSVMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbDanhsachSVMouseClicked
        // TODO add your handling code here:
        int row = tbDanhsachSV.getSelectedRow();
        cbbsinhvien.setSelectedItem((String) tbDanhsachSV.getModel().getValueAt(row, 0));
        cbbmonhoc.setSelectedItem((String) tbDanhsachSV.getModel().getValueAt(row, 1));
        cbbhocki.setSelectedItem((Integer) tbDanhsachSV.getModel().getValueAt(row, 2));
        txtdiemchuyencan.setText( tbDanhsachSV.getModel().getValueAt(row, 3).toString());
        txtdiemgiuaki.setText( tbDanhsachSV.getModel().getValueAt(row, 4).toString());
        txtdiemthiketthuc.setText( tbDanhsachSV.getModel().getValueAt(row, 5).toString());
        txtdiemTB.setText( tbDanhsachSV.getModel().getValueAt(row, 6).toString());
        txtxeploai.setText((String) tbDanhsachSV.getModel().getValueAt(row, 7));
        txtdtichluy.setText( tbDanhsachSV.getModel().getValueAt(row, 8).toString());
        txtghichu.setText((String) tbDanhsachSV.getModel().getValueAt(row, 9));
       
    }//GEN-LAST:event_tbDanhsachSVMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmNhapdiem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmNhapdiem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmNhapdiem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmNhapdiem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new frmNhapdiem().setVisible(true);
                } catch (Exception ex) {
                    Logger.getLogger(frmNhapdiem.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCapnhatDiem;
    private javax.swing.JButton btnnhapdiem;
    private javax.swing.JButton btnthoat;
    private javax.swing.JComboBox cbbDanhsachlopHP;
    private javax.swing.JComboBox cbbhocki;
    private javax.swing.JComboBox cbbmonhoc;
    private javax.swing.JComboBox cbbsinhvien;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbMaGV;
    private javax.swing.JLabel lbTen;
    private javax.swing.JPanel pnThongtin;
    private javax.swing.JTable tbDanhsachSV;
    private javax.swing.JTextField txtdiemTB;
    private javax.swing.JTextField txtdiemchuyencan;
    private javax.swing.JTextField txtdiemgiuaki;
    private javax.swing.JTextField txtdiemthiketthuc;
    private javax.swing.JTextField txtdtichluy;
    private javax.swing.JTextField txtghichu;
    private javax.swing.JTextField txtxeploai;
    // End of variables declaration//GEN-END:variables
}
